$(function(){

	function getQueryString(name){
      var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
      var r = window.location.search.substr(1).match(reg);
      if(r!=null)return  unescape(r[2]); return null;
  }

	(function(){
		var name = getQueryString("source");
		if(name === "yoparent-app"){
			$(".wv-home").remove();
			$(".wv-wrap").show();
			$(".app-print").show();
			$(".wv-layar").show();
			$(".twbox").hide().remove();
			$(".wv-btn-share").hide().remove();
			$(".wv-wrap .wv-header").hide();
			$(".wv-wrap .wv-content").css({top:'0px'});
			
			setTimeout(function(){
				wvMould.getData();
			},200);
		}
	})();

	FastClick.attach(document.body);

	if(AppStorage.getValueInLocalStorage("status") == "true"){
		window.location.href="result.html" + location.search;
	}

	$(".wv-btn-strat").on("click",function(){
		if($(this).hasClass("wv-btn-open")){
			$(this).parents(".wv-home").hide();
			$(".wv-wrap").show();
			$(".wv-layar").show();
			wvMould.getData();
		}
	});
	
	


	$(".wv-select").on("change blur select touchend",function(){
		var flag = true;
		//alert(1);
		$(".wv-select").each(function(){
			if($(this).val() == -1){
				flag = false;
			}
		});
		//alert(2);
		if($(this).hasClass("sex")){
			_evaluationResult.sex = $(this).val();
		}
		if($(this).hasClass("age")){
			_evaluationResult.age = $(this).val();
		}
		//alert(3);
		if(flag){
			//alert(4);

			$(".wv-layar").fadeOut(1000);
		}
	});
	
	/*result page*/
	$(".wv-layar-fx").on("click",function(){
		$($(this)).hide();
	});
	$(".wv-result .wv-btn-again").on("click",function(){
		AppStorage.removeValueInLocalStorage("status");
		window.location.href="index.html" + location.search;
	});
	$(".wv-result .wv-btn-share").on("click",function(){
		$(".wv-layar").show();
		setTimeout(function(){
			$(".wv-layar").hide();
		},2000);
	});

	var _hmt = _hmt || [];
      (function() {
        var hm = document.createElement("script");
        hm.src = "//hm.baidu.com/hm.js?c972f6ec6001ddcaf8bc97d0dc8d2f07";
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(hm, s);
      })();

});
Pace.on("done",function(){
	$(".wv-loading").hide();
});


  function isWeiXin(){
    var ua = window.navigator.userAgent.toLowerCase();
    if(ua.match(/MicroMessenger/i) == 'micromessenger'){
        return true;
    }else{
        return false;
    }
  }
  function getQueryString(name){
      var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
      var r = window.location.search.substr(1).match(reg);
      if(r!=null)return  unescape(r[2]); return "";
  }

  function getCookie(name){
    var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
    if(arr=document.cookie.match(reg))
    return unescape(arr[2]);
    else
    return null;
  }
  var openid = getQueryString("openid");
  if(isWeiXin()){

    if(!openid){
          openid = getCookie("openid");
    }

		var name = getQueryString("source");

    if(!openid && name !== "yoparent-app"){
      location.replace("http://weixin.winnovator.cn/entrance/fromSource?redirect="+encodeURIComponent(location.href));
    }
  }
